<template>
  <div>
    <a-card :bordered="false" class="table-card">
      <a-row :gutter="32" style="width: 80%; left: 10%; margin-top: 50px">
        <a-col :span="24" style="text-align: center">
          <a-form-item>
            <h2>集团简介</h2>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <div id="vditorEdit" name="description"></div>
        </a-col>
        <a-col :span="24" style="text-align: center; margin-top: 10px">
          <a-form-item>
            <a-button type="primary" @click="onUpdateCompany">保存</a-button>
          </a-form-item>
        </a-col>
      </a-row>
    </a-card>
  </div>
</template>
<script>
import { getBizCompany, updateBizCompany } from "@/api/biz/bizCompany";
import Vditor from "vditor";
import "vditor/dist/index.css";
export default {
  name: "BizCompany",
  components: {},
  data() {
    return {
      attachmentRefName: "addUploaderFile", // 标志表单是否含有附件
      editAttachmentRefName: "editUploaderFile",
      attachmentUploadStatus: true, // 记录的附件的上传状态
      uploaderButtonStatus: false, // 附件上传时按钮状态
      pageSizeOptions: ["10", "20", "30", "40", "50", "100", "200", "500"],
      showAddModal: false,
      showEditModal: false,
      contentEditorEdit: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 公司信息表格数据
      bizCompanyList: [],
      // 短信通知字典
      smsIsopenOptions: [],
      // OSS文件存储字典
      ossIsopenOptions: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        companyName: undefined,

        lianxiUser: undefined,
      },
      form: {},
      vditorToolbar: [
        // 将上传图片和录音按钮隐藏
        "emoji",
        "headings",
        "bold",
        "italic",
        "strike",
        "link",
        "|",
        "list",
        "ordered-list",
        "check",
        "outdent",
        "indent",
        "|",
        "quote",
        "line",
        "code",
        "inline-code",
        "insert-before",
        "insert-after",
        "|",
        "table",
        "|",
        "undo",
        "redo",
        "|",
        "fullscreen",
        "edit-mode",
        {
          name: "more",
          toolbar: [
            "both",
            "code-theme",
            "content-theme",
            "export",
            "outline",
            "preview",
            "devtools",
          ],
        },
      ],
    };
  },
  created() {
    this.handleUpdate();
  },
  methods: {
    handleUpdate(row) {
      const noticeId = "admin123";
      getBizCompany(noticeId).then((response) => {
        this.open = true;
        this.form = response.data;
        this.formId = response.data.id;
        this.$nextTick(() => {
          if (this.contentEditorEdit === "") {
            this.contentEditorEdit = new Vditor("vditorEdit", {
              height: 560,
              toolbarConfig: {
                pin: true,
              },
              toolbar: this.vditorToolbar,
              cache: {
                enable: false,
              },
              after: () => {
                this.contentEditorEdit.setValue(response.data.content || "");
              },
            });
          } else {
            this.contentEditorEdit.setValue(response.data.content || "");
          }
        });
      });
    },
    onGetCompany() {},

    onUpdateCompany() {
      this.form.content = this.contentEditorEdit.getValue();
      this.form.contenthtml = this.contentEditorEdit.getHTML();
      updateBizCompany(this.form).then((response) => {
        this.$message.success("修改成功", 3);
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        companyName: undefined,

        lianxiUser: undefined,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizCompanyAddForm.handleAdd());
    },
  },
};
</script>
<style scoped>
.table-card {
  min-height: calc(100vh - 120px) !important;
}
</style>
